attribute vec3 a_positionL;
attribute vec2 a_uv;

uniform mat4 u_wvpMatrix;
uniform mat4 u_wMatrix;
uniform vec3 u_eyePosition;

uniform sampler2D samplerHeightMap;
uniform float u_maxHeight;
uniform float u_fogStart;
uniform float u_fogLength;

varying vec2 v_uv;
varying float v_lerpValue;

void main()
{
	vec4 pos = vec4(a_positionL, 1.0);
	vec4 tex = texture2D(samplerHeightMap, a_uv);
	pos.y += (tex.r*3.0 + tex.g*2.0 + tex.b)*u_maxHeight;

	gl_Position = u_wvpMatrix * pos;

	v_uv = a_uv;
	v_lerpValue = clamp((distance(u_wMatrix * vec4(a_positionL, 1.0), vec4(u_eyePosition, 1.0)) - u_fogStart) / u_fogLength, 0.0, 1.0);
}
